//
//  ByAudioServices.m
//  laserdevice_ios
//
//  Created by pro on 17/1/19.
//  Copyright © 2017年 com.itboye. All rights reserved.
//

#import "ByAudioServices.h"

// 手机震动
#import <AudioToolbox/AudioToolbox.h>

@implementation ByAudioServices
{
    SystemSoundID _soundID;
}
static ByAudioServices *instance;

+ (id)shareInstance {
    static dispatch_once_t onceToken;
    //这个函数中的代码快任务只能执行一次。他是线程安全的。
    dispatch_once(&onceToken, ^{
        instance = [[ByAudioServices alloc] init];
    });
    return instance;
}
//实现一些限制方法，限制这个类始终只能创建一个对象，并且此对象不能销毁
+ (id)allocWithZone:(struct _NSZone *)zone {
    
    if (instance == nil) {
        instance = [super allocWithZone:zone];
    }
    return instance;
}


- (void)setType:(int)type {
    
    if (type == 0) {
        _soundID = kSystemSoundID_Vibrate;
    }
    if (type == 1) {
        _soundID = 1007;
    }
}
- (void)play {
    
    AudioServicesPlaySystemSound(_soundID);

}


@end
